$(function() {
	var rowNum = 1;
			var Extperson; //提取人id
				
				$("#handdatagrid").datagrid({
					rownumbers: false,
					nowrap: false,
					border: true,
					border: true,
					 width: $(window).width(),
					toolbar: '#bioGridToolbar',
				})
				var handdatagridPanel = $("#handdatagrid").datagrid("getPanel");
				handdatagridPanel.on("click", "a.add", function() {
					$("#biodlgadd").dialog({
						buttons: [{
								text: "添加",
								iconCls: "icon-save",
								handler: function() {
									rowNum = rowNum + 1;
									var table = "<div><table class='form_table' id='bioform_table2" + rowNum + "' border='1' cellspacing='0' cellpadding='0' width='100%' style='border-color: #EEF5FF;'margin-top:15px;'>" +
										"<tr>" +
										"<td id='td_left'     >" +
										"序号：" +
										"</td>" +
										"<td id='td_right'><input class='easyui-textbox' style='width:100%' readonly='readonly' value=" + rowNum + "></td>" +
										"<td id='td_left'     >" +
										"生物照片：" +
										"</td>" +
										"<td id='td_right'><input class='easyui-filebox'  name='file' data-options=" + "buttonText:'选择',prompt:'请选择文件...'" + " style='width:100%' /></td>"
										+
										"<td id='td_left'     >" +
										"物证名称：" +
										"</td>" +
										'<td class="td_right"><input class="easyui-textbox"  style="width:100%;" /></td>'

										+
										"</tr>" +
										"<tr>" +
										"<td id='td_left'     >" +
										"提取人：" +
										"</td>" +
										"<td><input class='tiquren' id='bioman" + rowNum + "' onclick='addMan(this)' style='width:100%' /></td>"

										+
										"<td id='td_left'     >" +
										"提取日期：" +
										"</td>" +
										"<td><input class='easyui-datebox'  style='width:100%' /></td>" +
										"<td id='td_left'     >遗留部位：</td>" +
										'<td class="td_right"><input class="easyui-textbox"  style="width:100%;" /></td>' +
										"</tr><tr>" +
										"<td id='td_left'     >类型：</td>"
										+
										"<td colspan='5'>"+	
										"<label style='margin-left: 20px;'>DNA</label><input type='radio' checked='checked' name='type" + rowNum + "' value=''>"
										+	"<label style='margin-left: 20px;'>血迹</label><input type='radio' name='type" + rowNum + "' value=''>"
										+	"<label style='margin-left: 20px;'>赤毛发</label><input type='radio' name='type" + rowNum + "' value=''>"
								         +   "<label style='margin-left: 20px;'>精斑</label><input type='radio' name='type" + rowNum + "' value=''>" 
								         +   "<label style='margin-left: 20px;'>唾液斑</label><input type='radio' name='type" + rowNum + "' value=''>"  
								         +   "<label style='margin-left: 20px;'>汗液</label><input type='radio' name='type" + rowNum + "' value=''>" 
								         +   "<label style='margin-left: 20px;'>皮屑</label><input type='radio' name='type" + rowNum + "' value=''>" 
								         +   "<label style='margin-left: 20px;'>指甲</label><input type='radio' name='type" + rowNum + "' value=''>" 
								         +   "<label style='margin-left: 20px;'>排泄物</label><input type='radio' name='type" + rowNum + "' value=''>" 
								         +   "<label style='margin-left: 20px;'>呕吐物</label><input type='radio' name='type" + rowNum + "' value=''>" 
								         +   "<label style='margin-left: 20px;'>骨骼</label><input type='radio' name='type" + rowNum + "' value=''>" 
								         +   "<label style='margin-left: 20px;'>病理组织</label><input type='radio' name='type" + rowNum + "' value=''>" 
								         +   "<label style='margin-left: 20px;'>其它生物物证</label><input type='radio' name='type" + rowNum + "' value=''></td>" +
										
										"</tr><tr><td id='td_left'     >提取方法：</td>" +
										"<td colspan='2'>"+
										'<input class="easyui-textbox"  style="width:100%;" />'+
										"</td>"+
										"<td id='td_left'     >基本特征：</td>" +
										"<td colspan='2'><input class='easyui-textbox'  style='width:100%;' /></td>" +
										"</tr><tr>" +
										"<td id='td_left'     >鉴定书上传：</td><td>" +
										"	<input class='easyui-filebox'  name='file' data-options=" + "buttonText:'选择',prompt:'请选择文件...'" + " style='width:100%' /></td>"
										+
										"<td id='td_left'     >提交指纹系统：</td><td>"
										+
										"<input    type='checkbox' name='a' value='1'></td>"
										+
										"<td id='td_left'     >	是否列入现场提取登记表：</td>"
										+
										"<td colspan='3'><input    type='checkbox' name='b' value='1'></td></tr></table></div>"
									$("#bioForm").append(table);
									$.parser.parse($("#bioForm").parent());
								}
							}, {
								text: "删除",
								iconCls: "icon-remove",
								handler: function() {
									if(rowNum == 1) {
										return;
									}
									$("#bioform_table2" + rowNum).remove();
									rowNum = rowNum - 1;
								}
							}, {
								text: "保存",
								iconCls: "icon-save",
								handler: function() {

								}
							}, {
								text: "取消",
								iconCls: "icon-cancel",
								handler: function() {
							$("#biodlgadd").dialog("close");
								}
							}

						]
					});
					$("#biodlgadd").dialog("open").dialog('setTitle', '生物基本信息新增');
				}).on("click", "a.manypicture", function() {
						$("#biodlgpic").dialog({
						buttons: [{
								text: "添加",
								iconCls: "icon-save",
								handler: function() {
								   	
								 }
								}, {
								text: "取消",
								iconCls: "icon-cancel",
								handler: function() {
							$("#biodlgpic").dialog("close");
								}
							}
						]
						});
					$("#biodlgpic").dialog("open").dialog('setTitle', '多图片上传');
				});
				
				$('#dl12').datalist({
					url: 'json.json',
					method: 'get',
					valueField: 'value',
					textField: 'text',
					lines: false,
					checkbox: true,
					singleSelect: false
				});
				$('#dl22').datalist({
					//url:'file:///E:/prompt.json',
					//method:'get',	
					valueField: 'value',
					textField: 'text',
					lines: false,
					checkbox: true,
					singleSelect: false
				});

				//移动按钮
				$("#dl_add2").click(function() {
					var rows = $("#dl12").datalist("getSelections");
					/*
					//方式1
					var rowArray = new Array();
					$(rows).each(function(i){
						var value = rows[i].value;
						var text = rows[i].text;
						var row = {
							value:value,
							text:text
						};
						rowArray.push(row);
						//删除
						var rowIndex = $("#dl1").datalist("getRowIndex", rows[i]);
						$("#dl1").datalist("deleteRow",rowIndex);
					});
					rowArray = rowArray.concat($("#dl2").datalist("getRows"));//合并
					var total = { "total":rowArray.length,rows:rowArray };
					$("#dl2").datalist("loadData",rowArray);
					*/
					//方式2
					$(rows).each(function(i) {
						var value = rows[i].value;
						var text = rows[i].text;
						var row = {
							value: value,
							text: text
						};
						//添加
						//$("#dl2").datalist("appendRow",row);
						$("#dl22").datalist("insertRow", {
							index: 0,
							row: row
						}); //作为第一条
						//删除
						var rowIndex = $("#dl12").datalist("getRowIndex", rows[i]);
						$("#dl12").datalist("deleteRow", rowIndex);
					});
					//移动完后重新加载dl2,否则显示不正常
					$("#dl22").datalist("loadData", $("#dl22").datalist('getRows'));
				});
				//移动按钮
				$("#dl_add_all2").click(function() {
					var data = $("#dl12").datalist("getData");
					var rows = data.rows;
					var rowsLength = rows.length;
					var indexArray = new Array();
					for(var i = 0; i < rowsLength; i++) {
						var value = rows[i].value;
						var text = rows[i].text;
						var row = {
							value: value,
							text: text
						};
						//添加
						$("#dl22").datalist("appendRow", row);
					}
					//删除
					var rows = $("#dl12").datalist('getRows');
					for(var i = rows.length - 1; i >= 0; i--) {
						$("#dl12").datalist("deleteRow", i);
					}
					//移动完后重新加载dl2,否则显示不正常
					$("#dl22").datalist("reload");
				});
				$("#dl_remove2").click(function() {
					var rows = $("#dl22").datalist("getSelections");
					/*
					//方式1
					var rowArray = new Array();
					$(rows).each(function(i){
						var value = rows[i].value;
						var text = rows[i].text;
						var row = {
							value:value,
							text:text
						};
						rowArray.push(row);
						//删除
						var rowIndex = $("#dl2").datalist("getRowIndex", rows[i]);
						$("#dl2").datalist("deleteRow",rowIndex);
					});
					rowArray = rowArray.concat($("#dl1").datalist("getRows"));//合并
					var total = { "total":rowArray.length,rows:rowArray };
					$("#dl1").datalist("loadData",rowArray);
					*/
					//方式2
					var rows = $("#dl22").datalist("getSelections");
					var rowArray = new Array();
					$(rows).each(function(i) {
						var value = rows[i].value;
						var text = rows[i].text;
						var row = {
							value: value,
							text: text
						};
						//添加
						//$("#dl1").datalist("appendRow",row);
						$("#dl12").datalist("insertRow", {
							index: 0,
							row: row
						}); //作为第一条
						//删除
						var rowIndex = $("#dl22").datalist("getRowIndex", rows[i]);
						$("#dl22").datalist("deleteRow", rowIndex);
					});
					//移动完后重新加载dl1,否则显示不正常
					$("#dl12").datalist("loadData", $("#dl12").datalist('getRows'));

				});
				$("#dl_remove_all2").click(function() {
					var data = $("#dl22").datalist("getData");
					var rows = data.rows;
					var rowsLength = rows.length;
					var indexArray = new Array();
					for(var i = 0; i < rowsLength; i++) {
						var value = rows[i].value;
						var text = rows[i].text;
						var row = {
							value: value,
							text: text
						};
						//添加
						$("#dl12").datalist("appendRow", row);
					}
					//删除
					var rows = $("#dl22").datalist('getRows');
					for(var i = rows.length - 1; i >= 0; i--) {
						$("#dl22").datalist("deleteRow", i);
					}
					//移动完后重新加载dl1
					$("#dl12").datalist("reload");
				});
			})


			function addMan(obj) {
				Extperson = obj.id;
				$("#biodlgMan").dialog({
						buttons: [{
								text: "确定",
								iconCls: "icon-save",
								handler: function() {
								   	var selVal = '';
				var rows = $("#dl22").datalist('getRows');
				for(var i = 0; i < rows.length; i++) {
					selVal = selVal + rows[i].text + ",";
				};
				var value = selVal.substring(1, selVal.length - 1);
				$('#' + Extperson).val(value);
				$("#biodlgMan").dialog("close");
								 }
								}
						]
						});
				$("#biodlgMan").dialog("open").dialog('setTitle', '选择提取人');
			};
			
			//多文件上传
			$('#biof').filebox({
				onChange: function(value) {
					var f = $(this).next().find('input[type=file]')[0]; 
					if(f.files && f.files[0]) {
						// 更换图片时清空原图片展示内容
						      
						$('#pioimage').html('');       
						for(var i = 0; i < f.files.length; i++) {        
							var reader = new FileReader(f.files[i]);        
							reader.onload = function(e) {
								//append为在元素中的末尾添加内容
								          
								$('#pioimage').append("<img src='" + e.target.result + "' width='200px' height='100px'>");        
							}        
							reader.readAsDataURL(f.files[i]);
						}    
					}  
				}
			})

			$("#editHandInfo").click(function() {
				$("#handtableinfo").hide();
				$("#handtableinfo_edit").show();

			})
			$("#handedit_back").click(function() {
				$("#handtableinfo").show();
				$("#handtableinfo_edit").hide();
			})